package face.pay.web.oem.controller;

import face.pay.constant.UserType;
import face.pay.entity.OemInfo;
import face.pay.entity.UserInfo;
import face.pay.security.annotation.CurrentUser;
import face.pay.security.exception.BaseException;
import face.pay.util.ResultMessage;
import face.pay.util.page.PageData;
import face.pay.util.page.PageParam;
import face.pay.vo.OemUserInfo;
import face.pay.web.oem.service.IOemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.math.BigDecimal;

/**
 * @Auther: zkj
 * @Date: 2019/7/3 13:53
 * @Description:
 */
@Controller
@RequestMapping("/oem")
public class OemController {

    @Autowired
    private IOemService iOemService;


    @RequestMapping("/oemList")
    public String manager(){

        return  "oem/oemList";
    }

    @RequestMapping("/info")
    public String info(@CurrentUser UserInfo loginUser, Model model) throws  BaseException{

        String type = loginUser.getType();
        OemInfo oemInfo =  null;

        if(UserType.OEM.equals(loginUser.getType())){
            oemInfo =  this.iOemService.getOemInfo(loginUser.getOemId());
            Double levelProfit =    oemInfo.getLevelProfit()==null?new Double(0):oemInfo.getLevelProfit();
            BigDecimal level_profit =  new BigDecimal(levelProfit.toString()).multiply(BigDecimal.valueOf(100));
            oemInfo.setLevelProfit(level_profit.doubleValue());
        }
        model.addAttribute("oemInfo",oemInfo);
        return  "oem/info";
    }

    @RequestMapping("/editOem")
    @ResponseBody
    public ResultMessage editOem(OemUserInfo oemInfo) throws BaseException {

        return  this.iOemService.editOem(oemInfo);

    }

    @RequestMapping("/editOemInfo")
    @ResponseBody
    public ResultMessage editOemInfo(OemInfo oemInfo,@CurrentUser UserInfo loginUser) throws BaseException {

        return  this.iOemService.editOemInfo(oemInfo,loginUser);

    }



    @RequestMapping("/queryData")
    @ResponseBody
    public PageData data(OemUserInfo oemUserInfo, PageParam pageParam) throws BaseException {

        return  this.iOemService.queryPage(oemUserInfo,pageParam);

    }


}
